package tushare

import (
	"tushare/model/mysql"
)

type Elg struct {
	Id                   int64   `json:"id"`
	TsCode               string  `json:"ts_code"`
	TotalBuyElgVol       int64   `json:"total_buy_elg_vol"`
	TotalSellElgVol      int64   `json:"total_sell_elg_vol"`
	SellElgVolProportion float64 `json:"sell_elg_vol_proportion"`
	TradeDateFrom        string  `json:"trade_date_from"`
	TradeDateTo          string  `json:"trade_date_to"`
	Days                 int64   `json:"days"`
	CreateDate           string  `json:"create_date"`
	BuySellJf            int64   `json:"buy_sell_jf"`
}

func ElgCreate(e Elg) {
	mysql.DB.Table("tushare_elg").Create(&e)
}

func ElgList(page, pageSize, days int64, tradeDate string) []Elg {
	page = page
	pageSize = pageSize
	offset := (page - 1) * pageSize

	elg := []Elg{}
	mysql.DB.Table("tushare_elg").Where("create_date = ? and days = ?", tradeDate, days).Order("buy_sell_jf DESC").Limit(pageSize).Offset(offset).Scan(&elg)
	return elg
}

func ElgCount(days int64, tradeDate string) int64 {
	var count int64
	mysql.DB.Table("tushare_elg").Where("create_date = ? and days = ?", tradeDate, days).Count(&count)
	return count
}
